package com.example.mvc.mapper;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.BookType;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookMapper {
    @Select("select * from book")
    List<Book> getBookList();


    //在BookMapper.xml实现
    List<Book>  getQueryBookList(String queryBookName);

    //获取书的类型
    @Select("SELECT * FROM booktype")
    List<BookType> getBookTypeList();

    //添加书籍
    @Insert("INSERT INTO book(card,name,type,autho,press,num) VALUE(#{card},#{name},#{type},#{autho},#{press},#{num})")
    int addBook(Book book);

    //修改
    @Update("UPDATE book SET card=#{card},name=#{name},type=#{type},autho=#{autho},press=#{press},num=#{num} WHERE bid=#{bid}")
    int updateBook(Book book);

    //删除
    @Delete("DELETE FROM book WHERE bid=#{bookId}")
   int deleteBookById(int bookId);

    //添加图书类型
    @Insert("INSERT INTO booktype(name) VALUE(#{name})")
    int addBookType(BookType bookType);
    //更新图书类型
    @Update("UPDATE booktype SET name=#{name} WHERE tid=#{tid}")
    int updateBookType(BookType bookType);
    //删除图书类型
    @Delete("DELETE FROM booktype WHERE tid=#{bookTypeId}")
    int deleteBookTypeById(int bookTypeId);

    //通过书的id获取书信息
    @Select("SELECT * FROM book WHERE bid=#{bookId}")
    Book getBookById(int bookId);

    //借出后同一种书要减掉库存量
    @Update("UPDATE book SET num=num-1 WHERE card=#{card} ")
    int reduceBookNum(Book book);


    //还书后同一种书要加库存量
    @Update("UPDATE book SET num=num+1 WHERE card=#{card} ")
    int addBookNum(Book book);

}
